home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / PASSDK30.ZIP;1 / DISK1.ZIP / PAS / SUBS / MIDI / MIDI.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-27  |  5.1 KB  |  305 lines

  1. /*#> */
  2.  
  3. /*$Author:   DCODY  $*/
  4. /*$Date:   27 Jun 1992 15:44:28  $*/
  5. /*$Header:   W:/sccs/midi/midi.c_v   1.2   27 Jun 1992 15:44:28   DCODY  $*/
  6. /*$Log:   W:/sccs/midi/midi.c_v  $
  7.  * 
  8.  *    Rev 1.2   27 Jun 1992 15:44:28   DCODY
  9.  * Made it test both input, output, and interrupts.
  10.  * 
  11.  *    Rev 1.1   25 Jun 1992 21:47:22   DCODY
  12.  * PAS2 update
  13.  * 
  14.  *    Rev 1.0   15 Jun 1992 10:42:56   BCRANE
  15.  * Initial revision.
  16. */
  17. /*$Logfile:   W:/sccs/midi/midi.c_v  $*/
  18. /*$Modtimes$*/
  19. /*$Revision:   1.2  $*/
  20. /*$Workfile:   midi.c  $*/
  21.  
  22. /*#<*/
  23.  
  24. ;    /*\
  25. ;---|*|----====< MIDI.C >====----
  26. ;---|*|
  27. ;---|*| Demonstration MIDI I/O code
  28. ;---|*|
  29. ;---|*| Media Vision, Inc. Copyright (c) 1992. All Rights Reserved
  30. ;---|*|
  31. ;    \*/
  32.  
  33.  
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include "mvmidi.h"
  37.  
  38.         // buffer storage for testing buffer I/O routines
  39.  
  40. #define BUFFLEN 100
  41.         char buff100[BUFFLEN];    // buff used to send/receive data
  42.         extern _MidiInFilter;
  43.  
  44.         // mode of operation
  45.  
  46. #define OUTPUTMODE 0x08
  47. #define INPUTMODE  0x04
  48. #define BLOCKMODE  0x02
  49. #define IRQMODE    0x01
  50.         int Mode        = 0;
  51.         int EnableMode    = 0;
  52.  
  53.         // for debug output in realtime
  54.  
  55.         char far *VidPtr = 0xb8000000;
  56.         char vidattr     = 0x2F;
  57.  
  58. main(argc,argv)
  59.     int argc;
  60.     char *argv[];
  61. {
  62. int n,count;
  63. unsigned int c;
  64. char *b;
  65.  
  66.     // process command line switches
  67.  
  68.         Commandline (argc,argv);
  69.  
  70.     // install & initialize the MIDI stuff
  71.  
  72.         mvMIDIEnable(EnableMode);
  73.         _MidiInFilter = 0;
  74.  
  75.     // receive data & display it...
  76.  
  77.         switch (Mode & (INPUTMODE|OUTPUTMODE)) {
  78.  
  79.             case INPUTMODE:
  80.  
  81.                 while (1) {
  82.  
  83.                     // fill the buffer with incrementing values
  84.  
  85.                     count = mvMIDIGetBuff(BUFFLEN,(b = &buff100[0]));
  86.  
  87.                     if (count) {
  88.                         while (count--)
  89.                             doprintit (*b++);
  90.                          // printf ("%02x  ",*b++ & 0xff);
  91.                     }
  92.  
  93.                     if ((c = mvMIDIGetByte()) < 256)
  94.                         doprintit (c);
  95.                      // printf ("%02x  ",c);
  96.  
  97.                     if (kbhit())
  98.                         DoExit(-1);
  99.  
  100.                 }
  101.  
  102.             case OUTPUTMODE:
  103.  
  104.                 while (1) {
  105.  
  106.                     // fill the buffer with incrementing values
  107.  
  108.                     for (n=0;n<BUFFLEN;n++)
  109.                         buff100[n] = c++;
  110.  
  111.                     mvMIDISendBuff(BUFFLEN,&buff100[0]);
  112.  
  113.                     mvMIDISendByte( (char) c++ );
  114.  
  115.                     if (kbhit())
  116.                         DoExit(-1);
  117.  
  118.                 }
  119.                 break;
  120.         }
  121. }
  122.  
  123.  
  124. ;    /*\
  125. ;---|*|----====< CommandLine >====----
  126. ;---|*|
  127. ;---|*| process the command line switches
  128. ;---|*|
  129. ;    \*/
  130.  
  131. int CommandLine(argc,argv)
  132.     int argc;
  133.     char *argv[];
  134. {
  135. char *s;
  136. int n,temp;
  137. long l;
  138.  
  139.         // the mode determines what we do in the main loop
  140.  
  141.         n = 1;
  142.         while (n < argc) {
  143.  
  144.             s = argv[n++];
  145.  
  146.             if (*s == '/') s++;
  147.             if (*s == '-') s++;
  148.  
  149.             switch (*s & 0x5f) {
  150.  
  151.                 case 'B':
  152.                     Mode  |= BLOCKMODE;
  153.                     break;
  154.  
  155.                 case 'O':
  156.                     Mode  |= OUTPUTMODE;
  157.                     break;
  158.  
  159.                 case 'I':
  160.                     Mode  |= INPUTMODE;
  161.                     break;
  162.  
  163.                 case 'Q':
  164.                     Mode  |= IRQMODE;
  165.                     break;
  166.  
  167.             }
  168.         }
  169.  
  170.     /* if no mode, just give helps and exit                             */
  171.  
  172.         if (!Mode) {
  173.             printf ("\nMedia Vision MIDI test program.\n\n");
  174.             printf ("To Use: DOS>MIDI [I] [O] [B] [Q]\n\n");
  175.             printf ("Where:  [I] for input testing.\n");
  176.             printf ("        [O] for output testing.\n");
  177.             printf ("        [B] for block I/O testing.\n");
  178.             printf ("        [Q] for using interrupts (polls by default).\n\n");
  179.             printf ("Type any key to exit the test.\n\n");
  180.             DoExit(0);
  181.         }
  182.  
  183.  
  184.     /* set the interrupt modes                                            */
  185.  
  186.         if ((Mode & INPUTMODE) & (Mode & IRQMODE))
  187.             EnableMode |= 1;
  188.  
  189.         if ((Mode & OUTPUTMODE) & (Mode & IRQMODE))
  190.             EnableMode |= 2;
  191.  
  192. }
  193.  
  194.  
  195. ;    /*\
  196. ;---|*|----====< DoExit >====----
  197. ;---|*|
  198. ;---|*| Disable the MIDI and exit to DOS
  199. ;---|*|
  200. ;    \*/
  201.  
  202. DoExit(cc)
  203.    int cc;
  204. {
  205.  
  206.     // kill the midi port
  207.  
  208.         mvMIDIDisable();
  209.         exit(cc);
  210. }
  211.  
  212. ;    /*\
  213. ;---|*|----====< shifts >====----
  214. ;---|*|
  215. ;---|*| Return -1 if any shift key (CTRL|ALT|LSHIFT|RSHIFT) is down
  216. ;---|*|
  217. ;    \*/
  218.  
  219. int shifts()
  220. {
  221.     _asm {
  222.  
  223.         push    es
  224.         sub     ax,ax
  225.         mov     es,ax
  226.         mov     al,es:[0x417]
  227.         pop     es
  228.         and     al,0Fh
  229.         neg     al
  230.         sbb     ax,ax
  231.     }
  232. }
  233.  
  234.  
  235. ;   /*\
  236. ;---|*|----====< doprinit >====----
  237. ;---|*|
  238. ;---|*| print a hex byte directly to the screen.
  239. ;---|*|
  240. ;    \*/
  241.  
  242. doprintit (char c)
  243. {
  244.     _asm {
  245.             push    es
  246.             push    di
  247.  
  248.             les     di,[VidPtr]
  249.             mov     ah,[vidattr]        ; get the attribute
  250.         ;
  251.         ; print the whole word and space
  252.         ;
  253.             mov     al,c
  254.             and     al,0F0h
  255.             mov     cl,4
  256.             shr     al,cl
  257.             call    prtit
  258.  
  259.             mov     al,c
  260.             and     al,0FH
  261.             call    prtit
  262.  
  263.             mov     al,20h            ; pad two spaces...
  264.             call    int1014
  265.             call    int1014
  266.  
  267.             cmp     di,808h-1
  268.             sbb     ax,ax
  269.             and     di,ax
  270.             not     ax                ; flip an attribute bit
  271.             and     al,10h            ; when the pointer rolls
  272.             xor     [vidattr],al    ; over to the top
  273.  
  274.             mov     word ptr [VidPtr],di
  275.  
  276.             pop     di
  277.             pop     es
  278.             jmp     overit
  279.  
  280.         ;
  281.         prtit:
  282.         ;
  283.         ; convert one nibble to a hex 0-F
  284.         ;
  285.             add     al,90h
  286.             daa
  287.             adc     al,0
  288.             add     al,40h
  289.             daa
  290.         ;
  291.         int1014:
  292.             cld
  293.             stosw
  294.             ret
  295.         ;
  296.         overit:
  297.     }
  298. }
  299.  
  300.  
  301. ;    /*\
  302. ;---|*| End of MIDI.C
  303. ;    \*/
  304.  
  305.